<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="面试公司" prop="interviewCompany">
      <el-input v-model="dataForm.interviewCompany" placeholder="面试公司"></el-input>
    </el-form-item>
    <el-form-item label="面试时间" prop="interviewTime">
      <el-input v-model="dataForm.interviewTime" placeholder="面试时间"></el-input>
    </el-form-item>
    <el-form-item label="面试职位" prop="interviewPosition">
      <el-input v-model="dataForm.interviewPosition" placeholder="面试职位"></el-input>
    </el-form-item>
    <el-form-item label="面试地点" prop="interviewAddress">
      <el-input v-model="dataForm.interviewAddress" placeholder="面试地点"></el-input>
    </el-form-item>
    <el-form-item label="来源" prop="interviewSource">
      <el-input v-model="dataForm.interviewSource" placeholder="来源"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="登录用户id" prop="uid">
      <el-input v-model="dataForm.uid" placeholder="登录用户id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          interviewCompany: '',
          interviewTime: '',
          interviewPosition: '',
          interviewAddress: '',
          interviewSource: '',
          remarks: '',
          uid: ''
        },
        dataRule: {
          interviewCompany: [
            { required: true, message: '面试公司不能为空', trigger: 'blur' }
          ],
          interviewTime: [
            { required: true, message: '面试时间不能为空', trigger: 'blur' }
          ],
          interviewPosition: [
            { required: true, message: '面试职位不能为空', trigger: 'blur' }
          ],
          interviewAddress: [
            { required: true, message: '面试地点不能为空', trigger: 'blur' }
          ],
          interviewSource: [
            { required: true, message: '来源不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          uid: [
            { required: true, message: '登录用户id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/interview/interviewinvitation/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.interviewCompany = data.interviewInvitation.interviewCompany
                this.dataForm.interviewTime = data.interviewInvitation.interviewTime
                this.dataForm.interviewPosition = data.interviewInvitation.interviewPosition
                this.dataForm.interviewAddress = data.interviewInvitation.interviewAddress
                this.dataForm.interviewSource = data.interviewInvitation.interviewSource
                this.dataForm.remarks = data.interviewInvitation.remarks
                this.dataForm.uid = data.interviewInvitation.uid
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/interview/interviewinvitation/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'interviewCompany': this.dataForm.interviewCompany,
                'interviewTime': this.dataForm.interviewTime,
                'interviewPosition': this.dataForm.interviewPosition,
                'interviewAddress': this.dataForm.interviewAddress,
                'interviewSource': this.dataForm.interviewSource,
                'remarks': this.dataForm.remarks,
                'uid': this.dataForm.uid
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
